package com.ktjy.service.impl;

import com.ktjy.entity.Page;
import com.ktjy.entity.SysUser;
import com.ktjy.mapper.UserMapper;
import com.ktjy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public List<SysUser> userList() {
        return userMapper.getUser();
    }

    @Override
    public int insert(SysUser sysUser) {
        return userMapper.addUser(sysUser);
    }

    @Override
    public int delete(SysUser sysUser) {
        return userMapper.deleteUser(sysUser);
    }

    @Override
    public SysUser selectByIdUser(SysUser sysUser) {
        return userMapper.selectByIdUser(sysUser);
    }

    @Override
    public int updateByIdUser(SysUser sysUser) {
        return userMapper.updateUser(sysUser);
    }

    @Override
    public SysUser selectAccount(SysUser sysUser) {
        return userMapper.selectAccount(sysUser);
    }

    @Override
    public Page findPageVo(SysUser sysUser, Integer pageNo, Integer pageSize) {
        Page page = new Page();
        //查询总记录数
        Integer count = userMapper.count(sysUser);
        page.setRows(pageSize);
        page.setTotal(count);
        page.setTotalPage(pageNo);
        //查询信息
        List<SysUser> list = userMapper.pageUser(sysUser, page.offset(), page.getRows());
        page.setList(list);
        return page;
    }
}
